<?php
  //============================================================================
  // ____________________________PLIGG TEAM ADDON_______________________________
  //
  // This file was created by AnAlienHolakres3  ||| XXXXX  XX     XX XXXX   XXXX
  // (c) 2007-2008                Jakub Holasek ||| XXXXX  XX     XX X      X
  // @last_update                    06/03/2008 ||| XX     XX     XX X  XX  X  XX
  // @version                              0.9  ||| XX     XXXXXX XX XXXXX  XXXXX
  //
  // This file can be used by Pligg community.
  //=============================================================================

 
  if ($_GET['team_id'] ){
                
                         
    include_once('Smarty.class.php');
    $main_smarty = new Smarty;
    
    include('config.php');
    include(mnminclude . 'teamlogs.php');    
    include(mnminclude . 'team.php'); 
    include(mnminclude.'html1.php');  
    include(mnminclude.'smartyvariables.php');                  
    
        
    if($current_user->user_id != $_POST['user_id']) {        
       echo "8409160188ERROR:{$main_smarty->get_config_vars('PLIGG_Shoutbox_Invalid_User')}!";
       die;    
    }    
    $team = new Team;
                           
    $team->check_id($_GET['team_id']);   
  
    
  // request for shoutbox saving
  if ($_POST['mode']==1) {  
    if ($shoutbox->check_message_exist()) {                    
         $shoutbox->save_shoutbox_values();
        
    }else echo "8409160188ERROR:{$main_smarty->get_config_vars('PLIGG_Shoutbox_No_Text')}!";
    die;
  }
           
            
 // request for shoutbox refresh
    if ($_POST['mode']==2) {         
    if ($shoutbox->check_last_shout() && $shoutbox->check_messages_count()){
    
    if ($shoutbox->is_update_neccessary()) {
        
         
        
         $actual_messages_count = $shoutbox->get_messages_count();
         $shoutbox->read_rest_shouts();
         $shoutbox_update_data = $shoutbox->get_shoutbox_data();
         
         if ($_POST['last_shout']==2) {           
                      $i++;
         }  
         foreach ($shoutbox_update_data as $shout) {
                                      
                  $i++;
                  
                  if ($i % 2 == 0){
                  $shout_row[] =2; 
                  $last_shout=2;
                  
                  } else {
                  $shout_row[] =1;     
                  $last_shout=1;
                  }                  
                  
                  $shoutbox_ids[] = $shout->shoutbox_id;
                  $shoutbox_messages[] = $shout->message;
                  $shoutbox_creator_names[] = $shout->user_login;
                  
                  
                  if ($language == "en"){
                  $shoutbox_times[] = $shout->setup_date;
                  
                  } else {                                       
                  $shoutbox_times[] = date('d.m.Y H:i',strtotime($shout->setup_date));                                       
                  
                  }
         }
                  echo "actual_count:" . $actual_messages_count;
                  echo "last_shout:" . $last_shout;
                  
                  $ids_count = count($shoutbox_ids);
                  for ($a=0;$a < $ids_count;$a++) {   
                      if ($shout_row[$a]==1) {
                            echo "<p class='first'>";
                            
                      } else if ($shout_row[$a]==2) {
                            echo "<p class='second'>";                          
                      
                      } 
                       echo '<span style="color:#747474">' . $shoutbox_times[$a] . ' <b><i>' .$shoutbox_creator_names[$a] . ':</i></b></span> '.
                             $shoutbox_messages[$a].'</p>';
                  
                  
                      
                   }                                                
                  
         
    } else {
       
    }                     
  } else { echo "error";
         }  
    
                
             
  }
}  
    
  function utf8_urldecode($str) {
    $str = preg_replace("/%u([0-9a-f]{3,4})/i","&#x\\1;",urldecode($str));
    return html_entity_decode($str,null,'UTF-8');
  }

?>
